<template>
  <div>
    <div class="flex border-bottom border-C0C4CC">
      <h3 class="f-normal">活跃空间</h3>
    </div>
    <div class="p-x-8">
      <div
        v-for="space in spaces"
        :key="space.id"
        class="easy-container-1 border-bottom flex p-x-8"
      >
        <router-link :to="`/spaces/${space.id}`">
          <el-avatar :src="space.avatar" />
        </router-link>
        <div class="flex-1 m-l-16">
          <div>
            <router-link :to="`/spaces/${space.id}`" class="f-normal title link">
              {{ space.title }}
            </router-link>
            <router-link :to="`/users/${space.owner.id}`" class="m-l-16 f-mini-plus info-deep link">
              <i class="el-icon-user"></i>
              {{ space.owner.nickname }}
            </router-link>
            <div class="float-right">
              <span title="点赞数">
                <svg-icon icon-name="like-fill" />
                <span>{{ space.voteCount.liked }}</span>
              </span>
                <span title="收藏数" class="m-l-10">
                <svg-icon icon-name="star-fill" />
                <span>{{ space.voteCount.collected }}</span>
              </span>
            </div>
          </div>
          <div class="m-b-10">{{ space.desc }}</div>
          <timeago2 :date-time="space.updated_at" pre-text="更新于" class="info-deep" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatSpacesList } from '@/components/spaces/format';

export default {
  name: 'active-spaces', // 活跃空间
  data() {
    return {
      spaces: [],
      loading: false,
    };
  },
  created() { this.loadSpaces(); },
  methods: {
    loadSpaces() {
      this.loading = true;
      this.$api.homepage.spaces()
        .then((res) => { this.spaces = formatSpacesList(res.data); })
        .catch(() => {})
        .then(() => { this.loading = false; });
    },
  },
};
</script>

<style></style>
